<?php
include_once "header.php";

if($_SESSION['kewenangan']!="administrator"){
	header("Location:beranda.php");
}

	$daftar_log = new Daftar_log_user();
	$data = $daftar_log->getAll();
	
	$Cur_page=1;
	$per_page=20;
	$Page_num = ceil(count($data)/$per_page);
	$dataplus = $Page_num * $per_page ;
	$datasel = count($data) - $per_page * ($Page_num - 1);
		
	if(isset($_GET['page'])){
	$Cur_page = $_GET['page'];
		if( $Cur_page >$Page_num){
			$Cur_page=$Page_num;
		}
		if( $Cur_page < 1 ){
			$Cur_page = 1;
		}
	} 
	
	if($datasel>0 && $Cur_page==$Page_num){
		$log = array_slice($data,$per_page * ($Cur_page -1));
	} else {$log = array_slice($data,$Cur_page, $per_page);
		}
	



?>

<div id="container">
	<div id="maincont">
		<?php include_once "menu_samping.php"; ?>
		<div id="mainright">
			<div id="title">
			Daftar Log Pengguna
			</div>
			<div id="body">	
			
			<table id="table2" cellspacing=0 cellpadding=4 width=50%>
				<tr>
					<th width=3%>No.</th>
					<th width=25%>Nama / NIP</th>
					<th width=10%>Waktu log</th>
					
					
				</tr>
				<?php
				$j=1;
				foreach($log as $Log){?>
				
				<tr>
					<td><?php echo $j+($per_page*($Cur_page-1)); ?></td>
					<td>
					<?php 
						$daftar_user = new Daftar_user();
						$user = $daftar_user->getByNip($Log->getNip());
						echo $user->getNama();
						echo "<br/>";
						echo "NIP.".$user->getNip()
					?>
					</td>
					
					<td><?php
					echo $Log->getWaktu_log();
					?></td>
					
								
					
				
				</tr>
				
				<?php $j++;} ?>
			</table>
			<?php
			if(empty($log)){
				echo "<table cellspacing=0 cellpadding=4 width=100%>";
				echo "<tr>";
				echo "<td>";
					echo "Data tidak tersedia.";	
				echo "</td>";			
				echo "</tr>";
				echo "</table>";
			}
			?>
			<br>
				
			</div>
			
			<?php 
			if($Page_num>0){ ?>

			<?php echo "Halaman ".$Cur_page." dari ".$Page_num."<br/>";?>
			<?php echo  "<a href='".$_SERVER['PHP_SELF']."?page=".(1)."'>Pertama  </a>";?>
			<?php echo  "<a href='".$_SERVER['PHP_SELF']."?page=".($Cur_page -1)."'>Sebelum  </a>";?>
			<?php echo "<a href='".$_SERVER['PHP_SELF']."?page=".($Cur_page+1)."'>Berikut  </a>";?>
			<?php echo  "<a href='".$_SERVER['PHP_SELF']."?page=".($Page_num)."'>Terakhir</a>";?>
			<?php }?>

			<?php
				if($Page_num==0){
					echo "Data tidak tersedia.";
				}

			?>
        </div>
	</div>
</div>
<?php
	include_once "footer.php";
?>

<script type="text/javascript">
	function del(){
	if(confirm('Apakah Anda yakin akan menghapus data ini?'))
	return true;
	else return false
	}
	
	onload=function(){
	
		document.form.onreset=function(){
			window.location="daftar_kewenangan_pengguna.php";
		}
	}
	
	function validasi(){
	var x = document.form.nip.value;
	if (x==""){
		alert('Isikan kata kunci terlebih dahulu!');
		return false;
	}
	}
	
	
	
</script>

